<?php

class Poll_Controller_Browse_Vote extends Nuo_Controller
{
	function execute($request)
	{
		// if (!Nuo::allow('blog.view')){return  'could not view blog';return;}

		$table = Nuo::getTable('poll');

		$userId = Nuo::getUserId();

		$id = $request -> getParam('poll_id');

		$answers = $request -> getParam('answer');

		$poll = $table -> find($id) -> current();

		if (!is_object($poll))
		{
			Nuo::redirect('poll');
		}

		if ($request -> isPost() && is_array($answers))
		{
			// check data and process vote
			$poll -> vote($userId, $answers);
		}

		return  $this -> render(array('item' => $poll));
	}

}
